EvilChatRoom {
	/*
	EvilChatRoom.new();
	*/
	var display,conversation,entry,view,userName,netAddr,oscResponder;
	
	*new { arg parentWindow=nil,usrName = "Noob",oscGroupPort=12000,bounds=Rect(0,0,600,200),color=Color.white;
		^super.new.init(parentWindow,usrName,oscGroupPort,bounds,color);
	}
	
	init { arg parentWindow=nil,usrName = "Noob",oscGroupPort=12000,bounds=Rect(0,0,600,200),color=Color.white;
		var displayColor,entryColor,textColor;
		
		netAddr = NetAddr("127.0.0.1",oscGroupPort);
		oscResponder = OSCresponder(nil,'/evilChat',{ |t,r,msg| { this.enterText(msg[1]) }.defer }).add;
		
		if(parentWindow == nil, {
			parentWindow = Window.new("EvilChatRoom",Rect(bounds.left,bounds.top,bounds.width+5,bounds.height+10));
		});
		
		view = FlowView.new(parentWindow,Rect(bounds.left,bounds.top,bounds.width,bounds.height));
		
		userName = usrName++": ";
		conversation = "";
		displayColor = color;
		entryColor = Color.new255(75,75,75);
		textColor = Color.black;
		
		display = TextView.new(view,Rect(0,0,bounds.width,bounds.height-25))
			.font_(Font.new("Helvetica",12))
			.editable_(false)
			.autohidesScrollers_(true)
			.hasVerticalScroller_(true)
			.string_(conversation)
			.background_(displayColor)
			.stringColor_(textColor)
			.canFocus_(false);
			
		entry = TextField.new(view,Rect(0,bounds.height*0.6,bounds.width,25))
			.background_(entryColor)
			.stringColor_(textColor)
			.focusColor_(Color.clear)
			.action_({ 
				|v|
				var entryString;
				entryString =  userName++v.value++"\n";
				this.enterText(entryString);
				netAddr.sendMsg("/evilChat",entryString);
				v.string_("");
				entry.focus(false);
				parentWindow.asView.focus(false);
				parentWindow.asView.focus(true);
				entry.focus(true);
			});
			
		parentWindow.front;
	}
	
	enterText { arg string;
		conversation = string++conversation;
		display.string_(conversation);
	}

}